Skip to content

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5533.

As far as I could tell, the (sub)title/captions were the only places where margins were ignored that didn't need to be ignored, so only needed to enable the margins at those places.

Example that margins can be set:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  labs(
    title    = "Plot of the mpg dataset",
    subtitle = "Engine displacement versus highway miles per gallon",
    caption  = "EPA fuel economy data"
  ) +
  theme(
    plot.title    = element_text(margin = margin(l = 20, b = 5.5)),
    plot.subtitle = element_text(margin = margin(l = 40, b = 5.5)),
    plot.caption  = element_text(margin = margin(r = 40)) 
  )

Created on 2023-11-29 with reprex v2.0.2

@teunbrand teunbrand added this to the ggplot2 3.5.0 milestone Dec 5, 2023
Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand
Copy link
Collaborator Author

Thanks for the review Thomas!

@teunbrand teunbrand merged commit 15bde2f into tidyverse:main Dec 6, 2023
@teunbrand teunbrand deleted the full_margins branch December 6, 2023 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

element_text() ignores left and right margins for some plot elements
2 participants